// house_pkg/pages/room/index.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    rooms: [],
    point: '',
    building: '',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({ point, building }) {
    this.fake(point, building)
  },
  fake(point, building) {
    // 伪造房间号
    const size = Math.floor(Math.random() * 5) + 4
    const rooms = []
    // 随机生成若干个房间号
    for (let i = 0; i < size; i++) {
      // 楼层号 1～20
      const floor = Math.floor(Math.random() * 19) + 1
      // 房间号 1～3
      const no = Math.floor(Math.random() * 2) + 1
      const room = `${floor}0${no}`
      // 判断不允许重复的房间号
      if (rooms.includes(room)) continue
      rooms.push(room)
      rooms.sort((a, b) => a - b)
    }
    this.setData({ rooms, point, building })
  },
})
